<template>
  <div :class="['header',headerClass]">
    <div class="name">
      <h2>{{website.webName}}</h2>
    </div>
    <div class="opt">
      <div class="search">
        <div class="search-img"></div>
        <input class="search-input" type="text">
      </div>
      <div class="menu">
        <ul>
          <li><router-link to="/" :class="activeIndex === 1 ? 'menu-active' : ''">首页</router-link></li>
          <li><router-link to="/category" :class="activeIndex === 2 ? 'menu-active' : ''">分类</router-link></li>
          <li><router-link to="/timeline" :class="activeIndex === 3 ? 'menu-active' : ''">时间轴</router-link></li>
          <li>
            <el-dropdown trigger="click">
                <span>
                  <a href="javascript:;">外链<i class="el-icon-arrow-down el-icon--right"></i></a>
                </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-for="item in hrefList" :key="item.bannerId"><a style="text-decoration: none;color: #000" :href="item. bannerHref">{{item.bannerName}}</a></el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Header',
  props: {
    headerClass: {
      default: 'fixed-header'
    },
    activeIndex: {
      default: 1
    }
  },
  data () {
    return {
      hrefList: [],
      website: {}
    }
  },
  methods: {
    getWebsite () {
      this.$http.get('api/website').then(data => {
        this.website = data.data
      })
    },
    getHrefList () {
      this.$http.get('api/href').then(data => {
        this.hrefList = data.data
      })
    }
  },
  created () {
    this.getWebsite()
    this.getHrefList()
  }
}
</script>

<style scoped lang="scss">
.header{
  height: 60px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  .name{
    padding-left: 15px;
  }
  .opt{
    display: flex;
    align-items: center;
    .search{
      height: 30px;
      width: 200px;
      background-color: #fff;
      border-radius: 16px;
      border: 1px solid grey;
      overflow: hidden;
      display: flex;
      .search-img{
        height: 30px;
        width: 30px;
        background: url("../assets/search.svg") no-repeat center;
      }
      .search-input{
        display: block;
        height: 30px;
        border: none;
        outline: none;
      }
    }
    .menu{
      width: 300px;
      margin: 0 30px;
      ul{
        height: 60px;
        list-style: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        li{
          width: 50px;
          text-align: center;
          a{
            text-decoration: none;
          }
          a:hover{
            border-bottom: 2px solid greenyellow;
          }
        }
      }
    }
  }
  .menu-active{
    border-bottom: 2px solid greenyellow !important;
  }
}

.absolute-header{
  position: absolute;
  left: 0;
  top: 0;
  background-color: rgba(255,255,255,0);
  border-bottom: none;
  .name>h2{
    color: #fff;
  }
  a{
    color: #fff;
  }
}
.fixed-header{
  position: fixed;
  left: 0;
  top: 0;
  background-color: rgba(255,255,255,1);
  border-bottom: 1px solid greenyellow;
  .name>h2{
    color: #000;
  }
  a{
    color: #000;
  }
}
</style>
